//
//  DiscoverDetailController.m
//  NewProject
//
//  Created by l wb on 2018/6/1.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "DiscoverDetailController.h"
#import "DiscoverDetailCell.h"
@interface DiscoverDetailController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation DiscoverDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"详情";
    self.tableView.estimatedRowHeight = 404;
    NSLog(@"%@---%@",self.titleStr,self.type);
    if (!self.model) {
        [self getNewsInformationDataFromNetWithType:self.type];
    }
    
}
-(void)getNewsInformationDataFromNetWithType:(NSString *)type{
    BmobQuery *query;
    if ([self.titleStr isEqualToString:@"专家预测"]) {
     
        query = [BmobQuery queryWithClassName:@"ExpertsPredict"];
    }else{
        query = [BmobQuery queryWithClassName:@"Skills"];
        
        
    }

    [query whereKey:@"type" equalTo:[NSString stringWithFormat:@"%@",self.type]];
    
    [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        if (!error) {
            NSLog(@"%@",array);
            if (array.count == 0) {
                [self getNewsInformationDataFromNetWithType:self.type];
            }else{
                self.model = array[0];
                [self.tableView reloadData];
            }
           
            
        }
        
        
    }];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.model) {
        return 1;
    } else {
        return 0;
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DiscoverDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DiscoverDetailCell"];
    cell.titleLab.text = [self.model objectForKey:@"title"];
    cell.contentOneLab.text = [self.model objectForKey:@"contentOne"];

    cell.contentTwoLab.text = [self.model objectForKey:@"contentTwo"];
    [cell.showImg sd_setImageWithURL:[self.model objectForKey:@"showImg"]];
    
    
    
    
    
    return cell;
}
@end
